<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('操作时间')">
              <j-date
                 :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }" valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                 :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }" valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('功能模块')">
              <j-dict-select-tag
                :placeholder="$t('请选择功能模块')"
                v-model="queryParam.modelType"
                dictCode="bis_manage_log.model_type"
              />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作类型')">
                <j-dict-select-tag
                  :placeholder="$t('请选择操作类型')"
                  v-model="queryParam.operateType"
                  dictCode="operate_type"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作员')">
                <j-dict-select-tag
                  :placeholder="$t('请选择操作员')"
                  v-model="queryParam.createBy"
                  dictCode="sys_user,realname,realname"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作内容')">
                <a-input :placeholder="$t('请输入操作内容')" v-model="queryParam.operateContent"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('管理日志'))">{{$t('导出')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无图片')}}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">{{$t('编辑')}}</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">{{$t('更多')}} <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">{{$t('详情')}}</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
                  <a>{{$t('删除')}}</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <bis-manage-log-modal ref="modalForm" @ok="modalFormOk"></bis-manage-log-modal>
  </a-card>
</template>

<script>
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import BisManageLogModal from './modules/BisManageLogModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'BisManageLogList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BisManageLogModal,
  },
  data() {
    return {
      moment,
      description: '管理日志管理页面',
      // 表头
      columns: [
        {
          title: this.$t('操作时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('功能模块'),
          align: 'center',
          dataIndex: 'modelType_dictText',
        },
        {
          title: this.$t('操作类型'),
          align: 'center',
          dataIndex: 'operateType_dictText',
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: this.$t('操作内容'),
          align: 'center',
          dataIndex: 'operateContent',
          customCell: function (t, r) {
            return {
              style: {
                textAlign: 'left',
                maxWidth: '580px',
                whiteSpace: 'pre-wrap',
                wordBreak: 'break-all'
              },
            }
          },
          // customRender: (text, record, index) => {
          //   const answer = text.split('；')
          //   return answer.map((item) => {
          //     return <li>{item}</li>
          //   })
          // },
        },
      ],
      url: {
        list: '/system/bisManageLog/list',
        delete: '/system/bisManageLog/delete',
        deleteBatch: '/system/bisManageLog/deleteBatch',
        exportXlsUrl: '/system/bisManageLog/exportXls',
        importExcelUrl: 'system/bisManageLog/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'datetime', value: 'createTime', text: this.$t('操作时间') })
      fieldList.push({ type: 'int', value: 'modelType', text: this.$t('功能模块'), dictCode: 'bis_manage_log.model_type' })
      fieldList.push({ type: 'int', value: 'operateType', text: this.$t('操作类型'), dictCode: 'operate_type' })
      fieldList.push({ type: 'string', value: 'createBy', text: this.$t('操作员'), dictCode: 'sys_user,realname,realname' })
      fieldList.push({ type: 'Text', value: 'operateContent', text: this.$t('操作内容'), dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>